require 'rubygems'
require 'eventmachine'
require 'source/asymy/asymy'
require 'pp'
require 'connection_pool'

EventMachine::run {

   opts = {:target => "localhost",
                             :port => 3306,
                             :username => "wilkboar_ties",
                             :password => "ties",
                             :database => "local_leadgen_dev"}

# non pool
conns = []
20.times {conns << Asymy::Connection.new(opts) } 
outstanding = 0

# some long ones
0.upto(10) do |i|
   outstanding += 1
   conns[i].exec("select COUNT(*) from user_sessions") {|cols, rows| pp 'big', [i, rows.size]
	outstanding -= 1
	EM.stop if outstanding == 0
	}
end

# some short ones, and using a pool for good measure :)
# pool
pool = ConnectionPool.new 10, opts
10.times { |i|
  outstanding += 1
  pool.exec_when_available("select COUNT(*) from users") {|cols, rows|
        pp 'small', [i, rows.size]
	outstanding -= 1
	EM.stop if outstanding == 0

  }
}

} # EM run
